export interface buildingsList {
    id: number;
    name: string;
    pid: number;
    leaf: number;
    children: Array<buildingChildren>;
};

export interface buildingChildren {
    id: number;
    name: string;
    pid: number;
    leaf: number;
    children?: any;
};

export function transformBuildingData(buildings: any[]): any[] {
    return buildings.map(building => {
        const transformed: any = {
            title: building.name,
            pid: building.pid,
            key: building.id.toString(),
        };

        if (building.children && building.children.length > 0) {
            transformed.children = transformChildrenData(building.children);
        }

        return transformed;
    });
}

function transformChildrenData(children: buildingChildren[]): any[] {
    return children.map(child => {
        const transformed: any = {
            title: child.name,
            pid: child.pid,
            key: child.id.toString(),
        };

        if (child.children && child.children.length > 0) {
            transformed.children = transformChildrenData(child.children);
        }

        return transformed;
    });
}